Skip to content

TestAssertionFailure: retain full error chain in message #666

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

rursprung
Copy link

so far the conversion from an Error to a TestAssertionFailure meant that all information about the source errors were lost. often, the Display implementation for Error implementations does not include the source information since that should instead be retrieved via source. while this has not yet been made into an official API guideline (see rust-lang/api-guidelines#210) this is nevertheless being followed.

various crates like anyhow or eyere take care of pretty-printing the error chain on failure, however this does not work with googletest since googletest::Result has TestAssertionFailure as the error type which swallows any Error and only keeps the message.

to resolve this a simple error chain implementation is added to the From implementation which pretty-prints the error chain.

example:

Error: test3

Caused by:
1: test2
2: test1

fixes #657

so far the conversion from an `Error` to a `TestAssertionFailure` meant
that all information about the source errors were lost. often, the
`Display` implementation for `Error` implementations does not include
the source information since that should instead be retrieved via
`source`. while this has not yet been made into an official API
guideline (see [rust-lang/api-guidelines#210]) this is nevertheless
being followed.

various crates like `anyhow` or `eyere` take care of pretty-printing the
error chain on failure, however this does not work with `googletest`
since `googletest::Result` has `TestAssertionFailure` as the error type
which swallows any `Error` and only keeps the message.

to resolve this a simple error chain implementation is added to the
`From` implementation which pretty-prints the error chain.

example:

```
Error: test3

Caused by:
1: test2
2: test1
```

fixes google#657

[rust-lang/api-guidelines#210]: rust-lang/api-guidelines#210
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

#[gtest]: print full error chain if test function returns an error
1 participant